package com.ziyun.pop.web.modules.mercharReport.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.ziyun.pop.common.utils.FileUtil;
import com.ziyun.pop.common.utils.JsonUtils;
import com.ziyun.pop.common.utils.UserUtils;
import com.ziyun.pop.modules.mercharReport.entity.ReportStoreOutVO;
import com.ziyun.pop.modules.mercharReport.entity.ReportStoreStockMaterialEntity;
import com.ziyun.pop.modules.mercharReport.entity.ReportStoreStockMaterialVo;
import com.ziyun.pop.modules.mercharReport.service.ReportStoreStockMaterialService;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 门店库存明细表
 *
 * @author llc
 * @email 787254039@qq.com
 * @date 2018-11-22 10:13:49
 */
@RestController
@RequestMapping("mercharReport/storestockmaterial")
public class ReportStoreStockMaterialController {
    @Autowired
    private ReportStoreStockMaterialService reportStoreStockMaterialService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("mercharReport:storestockmaterial:list")
    public R list(@RequestParam Map<String, Object> params){
        params.put("sellerId",UserUtils.getCurentUser().getSellerId());
        return reportStoreStockMaterialService.list(params);
    }

    /**
     * excel 导出
     */
    @RequestMapping("/exportExcel")
    public void exportExcel(HttpServletRequest request, HttpServletResponse response) {
        String data = request.getParameter("postData");
        Map<String, Object> params = JsonUtils.string2Map(data);
        params.put("sellerId", UserUtils.getCurentUser().getSellerId());
        // 查询列表数据
        List<ReportStoreStockMaterialVo> list = reportStoreStockMaterialService.exportExcel(params);
        FileUtil.exportExcel(list, "库存明细表", "库存明细表", ReportStoreStockMaterialVo.class, "库存明细表.xls", response);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{stockMaterialId}")
    @RequiresPermissions("mercharReport:storestockmaterial:info")
    public R info(@PathVariable("stockMaterialId") Integer stockMaterialId){
        ReportStoreStockMaterialEntity storeStockMaterial = reportStoreStockMaterialService.getById(stockMaterialId);
        return R.ok().put("storeStockMaterial", storeStockMaterial);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("mercharReport:storestockmaterial:save")
    public R save(@RequestBody ReportStoreStockMaterialEntity storeStockMaterial){
        reportStoreStockMaterialService.save(storeStockMaterial);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("mercharReport:storestockmaterial:update")
    public R update(@RequestBody ReportStoreStockMaterialEntity storeStockMaterial){
        ValidatorUtils.validateEntity(storeStockMaterial);
        reportStoreStockMaterialService.updateById(storeStockMaterial);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("mercharReport:storestockmaterial:delete")
    public R delete(@RequestBody Integer[] stockMaterialIds){
        reportStoreStockMaterialService.removeByIds(Arrays.asList(stockMaterialIds));
        return R.ok();
    }

}
